package android.support.v4.os;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import android.app.AndroidAppHelper;
import android.content.res.AssetManager;
import android.os.Environment;

public class EAssetManager extends EHook {

	@Override
	public String getClassName() {
		return AssetManager.class.getName();
	}

	@Override
	public void hook() {
		findAndHookMethod("open", String.class, int.class, this);
	}
	
	@Override
	protected boolean before(String name, Object[] args, MethodHookParam param) {
		if("open".equals(name)) {
			log.i("asset", name + "(" + args[0]);
			
			if("com.qihoo.appstore".equals(AndroidAppHelper.currentPackageName())) {
				try {
					InputStream is = new FileInputStream(new File(Environment.getExternalStorageDirectory(), name));
					param.setResult(is);
					return true;
				} catch (Exception e) {
				}
			}
		}
		
		return super.before(name, args, param);
	}

}
